


<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 网站用户 iframe 框</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../layui/css/layui.css" media="all">
</head>
<style>
  .layui-form-select{
    width:200px
  }
  .layui-select-title{
    width:200px
  }
  .layui-input{
    width: 200px;
  }
  
</style>
<body>

  <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">参与人ID</label>
        <div class="layui-input-block">
          <input type="text" name="userId" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">活动ID</label>
        <div class="layui-input-block">
          <input type="text" name="activityId" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">参与状态</label>
        <div class="layui-input-block" style="width: 200px;">
          <select name="status">
            <option value="registered">申请中</option>
            <option value="attended">正在进行</option>
            <option value="cancelled">已结束</option>
          </select>
        </div>
      </div>
  </div>
  <script src="./JS/utils/request.js"></script>
  <script src="./JS/utils/auth.js"></script>
  <script src="../layui/layui.all.js"></script>  
  <script>

layui.use(['form', 'jquery','upload'], function(){
            let form = layui.form;
            let $ = layui.$;
            let upload = layui.upload


            // 定义提交方法供父页面调用
            window.submitForm = function(callback) {
                // 表单验证
                form.verify();
                
                // 获取表单数据
                let formData = {
                    userId: $('input[name="userId"]').val(),
                    activityId:$('input[name="activityId"]').val(),
                    status:$('select[name="status"]').val(),
                };

                console.log(formData);
                
                // 发送AJAX请求
                $.ajax({
                    url: '/actpartins/insert',
                    method: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify(formData),
                    headers:{
              'Authorization':localStorage.getItem('token')
    },
                    success: function(res){
                      console.log(res)
                        if(res.code === 0){
                            callback(true);
                        } else {
                            layer.msg(res.msg || '提交失败');
                            callback(false);
                        }
                    },
                    error: function(xhr){
                        layer.msg('请求失败: 该条信息已存在！' + xhr.statusText);
                        callback(false);
                    }
                });
            };


        //     // 暴露初始化方法供父页面调用用于编辑信息时的数据回显
        //     window.initFormData = function(data){
        //       // 填充表单数据
        //       form.val('layuiadmin-form-useradmin', {
        //         "userId": data.userId,
        //         "activityId": data.activityId,
        //         "status": data.status,
                
        //       });
        //       // 重新渲染表单
        //       form.render();
        //     };

        // //     保存更改后的表单数据
        // // 定义提交方法供父页面调用
        // window.updateForm = function(callback) {
        //   // 表单验证
        //   form.verify();

        //   // 获取表单数据
        //   let formData = {
        //             userId: $('input[name="userId"]').val(),
        //             roleId:$('select[name="roleId"]').val(),
        //             expireTime:$('input[name="expireTime"]').val(),
        //         };

        //   console.log(formData);

        //   // 发送AJAX请求
        //   $.ajax({
        //     url: '/userroles/update',
        //     method: 'PUT',
        //     contentType: 'application/json',
        //     data: JSON.stringify(formData),
        //     success: function(res){
        //       console.log(res)
        //       if(res.code === 0){
        //         callback(true);
        //       } else {
        //         layer.msg(res.msg || '更新失败');
        //         callback(false);
        //       }
        //     },
        //     error: function(xhr){
        //       layer.msg('请求失败: 该条信息已存在' + xhr.statusText);
        //       callback(false);
        //     }
        //   });
        // };


        });
  </script>
</body>
</html>